<?php
session_start();


$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$webpage = $_POST['webpage'];

include("functions.php");

$unique = genKey();//generate Unique KEY
echo "loading Chat...";


$sql = "INSERT INTO `user` (`FirstName`, `LastName`, `Email`, `Password`, `Webpage`, `Session`) VALUES ('{$firstname}', '{$lastname}', '{$email}', NULL, '{$webpage}', '{$unique}');";
mysql_query($sql);


$sql = "SELECT idUser FROM `user` WHERE `Session` = '{$unique}'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
	$_SESSION['SESS_MEMBER_ID'] = $row['idUser'];
}


$_SESSION['chat'] = $unique;

$chatID = makeChat($_SESSION['chat'], $_SESSION['SESS_MEMBER_ID']);

$_SESSION['chatID'] = $chatID;

mysql_free_result($result);

mysql_close($link);

header("Refresh: 1; URL=chat.php");
?>
